﻿using Microsoft.AspNetCore.Mvc;
using ProductionManage.Models.DataModel;
using ProductionManage.Models.Products;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Numerics;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using wangyaxin.Wyx;
using wangyaxin.Wyx.Dto;

namespace wangyaxin.Web.WyxController
{
    public class VendorController : Controller
    {

        private readonly VendorAppService _vendorAppService;

        public VendorController(VendorAppService vendorAppService)
        {
            _vendorAppService = vendorAppService;
        }

        public IActionResult Vendor()
        {
            return View();
        }
        
        public IActionResult Addvendor()
        {
            return View();
        }

        public IActionResult updatevendor()
        {
            return View();
        }
        /// <summary>
        /// 获取产品列表--王亚鑫
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetVendorList(string VendorCode, string VendorName, string VendorEnName)
        {
            var list = await _vendorAppService.SelectVendor(VendorCode, VendorName, VendorEnName);
            return Ok(list);
        }

        /// <summary>
        /// 添加产品--王亚鑫
        /// </summary>
        /// <param name="input">产品数据传输对象</param>
        /// <returns></returns>
        
        [HttpPost]
        public async Task<IActionResult> AddVendorster(CreateVendorDto createVendorDto)
        {
            var ster = _vendorAppService.AddVendor(createVendorDto);
            return Json("ster");
        }

        /// <summary>
        /// 删除供应商--王亚鑫
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> DeleteVendorster(int id)
        {
            var deleteid = _vendorAppService.DeleteVendor(id);
            return Json(deleteid);
        }

        /// <summary>
        /// 恢复产品--王亚鑫
        /// </summary>
        /// <param name="id">产品ID</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetVendorByIdData(int id)
        {
            var result = await _vendorAppService.SelectById(id);
            return Ok(result);
        }


        /// <summary>
        /// 恢复产品--王亚鑫
        /// </summary>
        /// <param name="id">产品ID</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> UpdateVendorByIdData(UpdateVendorDto updateVendorDto)
         {
            var result =  _vendorAppService.UpdateVendor(updateVendorDto);
            return Json(new
            {
                code = "200",
                msg = "更新成功",
            });
        }
    }
}
